package com.ljkj.lawyer.lawyer.dao;

import com.ljkj.lawyer.lawyer.entity.LawyerEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface LawyerDao extends JpaRepository<LawyerEntity, Integer> {

    @Transactional
    @Modifying
    @Query(value = "update lawyer set is_last = 0 where member_id = ?1", nativeQuery = true)
    int updateAllLawyerByMemberId(Integer memberId);

    @Query(value = "select * from lawyer where member_id =?1 and is_last = 1", nativeQuery = true)
    LawyerEntity getLastLawyerInfoByMemberId(Integer memberId);

    @Query(value = "select * from lawyer where member_id =?1 order by create_time desc", nativeQuery = true)
    Page<LawyerEntity> getLawyerHistoryByMemberId(Integer memberId, Pageable pageable);


    @Query(value = "select * from lawyer where is_last = 1 order by create_time desc", nativeQuery = true)
    Page<LawyerEntity> getLawyerList(Pageable pageable);

    @Query(value = "select * from lawyer where is_last = 1 and member_id = ?1 order by create_time desc", nativeQuery = true)
    Page<LawyerEntity> searchLawyerList(Integer memberId, Pageable pageable);
}
